home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Sherlock 2.0 / DevLibSrc / Main_DevLib / LIBend.c < prev    next >
Text File  |  1996-02-09  |  2KB  |  137 lines

  1. /*
  2.     devlib: General program termination module.
  3.  
  4.     source:  LIBend.c
  5.     started: November 4, 1993.
  6.     version:
  7.         October 26, 1995.
  8.             Call w_applEvent in end_wait_for_exit only if USE_MAC_TOOLBOX not defined.
  9.         September 25, 1995.
  10.             Added support for Code Warrior.
  11.         January 7, 1994.
  12. */
  13.  
  14. #include "LIBlib.h"
  15.  
  16. #include "LIBend.h"
  17. #include <LIBlog.h>
  18. #include <LIBos.h>
  19.  
  20. #if defined(THINK_C) || defined(SYMANTEC_C) || defined(__MWERKS__)
  21.     #include <Mac_gui.h>
  22. #endif
  23.  
  24. #include <stdlib.h>        /* for _exitting().    */
  25.  
  26. /*
  27.     Forward declarations of internal routines.
  28. */
  29. static void    end_wait_for_exit    (char * message);
  30. static void undo_interrupts        (void);
  31.  
  32. /*
  33.     A signigicant system error has occured.
  34.  
  35.     Wait for the user to choose quit so that the error message is sure
  36.     to be seen, then close all files and exit.
  37. */
  38. void
  39. end_abort(void)
  40. {
  41.     end_wait_for_exit("\nChoose quit (or command q) immediately!\n");
  42.  
  43.     end_close_all();
  44.     log_close();
  45.     undo_interrupts();
  46.     abort();
  47. }
  48.  
  49. /*
  50.     The program is finished:  Exit after waiting for quit or a keystroke.
  51. */
  52. void
  53. end_done(void)
  54. {
  55.     end_wait_for_exit("\nChoose quit (or command q) to exit.\n");
  56.  
  57.     end_close_all();
  58.     log_close();
  59.     undo_interrupts();
  60.     exit(0);
  61. }
  62.  
  63. /*
  64.     Quit has been chosen: close all files and exit immediately.
  65. */
  66. void
  67. end_quit(void)
  68. {
  69.     ecnls(2); es(lib_program_name); es(" terminated by user.\n");
  70.     end_close_all();
  71.     main_quit();
  72.     log_close();
  73.     undo_interrupts();
  74.     exit(0);
  75. }
  76.  
  77. /*
  78.     There has been an argument error.  Wait for the user to choose quit.
  79. */
  80. void
  81. end_usage(void)
  82. {
  83.     end_wait_for_exit("\nChoose quit (or command q) now.\n");
  84.  
  85.     end_close_all();
  86.     log_close();
  87.     undo_interrupts();
  88.     exit(0);
  89. }
  90.  
  91. /*
  92.     Wait for the user to choose quit or hit a key.
  93. */
  94. static void
  95. end_wait_for_exit(char * message)
  96. {
  97.     static int abort_flag = FALSE;
  98.  
  99.     #if defined(THINK_C) || defined(SYMANTEC_C) || defined(__MWERKS__)
  100.  
  101.         es(message);
  102.  
  103.         /* Make sure we call end_wait_for_exit at most once. */
  104.         if (!abort_flag) {
  105.             abort_flag = TRUE;
  106.                 
  107.             /*
  108.                 Wait for quit to be chosen.
  109.                 Don't call w_applEvent if we are using the console package!
  110.             */
  111.             #ifndef USE_MAC_TOOLBOX
  112.                 while(w_applEvent(0) == TRUE) {
  113.                     ;
  114.                 }
  115.             #endif
  116.         }
  117.  
  118.     #endif
  119. }
  120.  
  121. static void
  122. undo_interrupts(void)
  123. {
  124.  
  125. #ifdef THINK_C
  126.  
  127.     #if 0 // This appears not to work in version 7 of Think C.
  128.         /*
  129.             _exiting(1)        call all installed shutdown routines.
  130.              _exiting(0)        call only routines installed with "_atexit."
  131.         */
  132.         _exiting(0);
  133.     #endif
  134. #endif
  135.  
  136. }
  137.